<template>
	<view class="news">
		<view class="contnet">
			<view class="index_contnet">
				<view class="index_contnet_item" v-for="(item,index) in list" @click="Godetail(item.newsId)">
					<u-image width="100%" :showLoading="true" mode="widthFix" :src="item.image"></u-image>
					<view class="text">
						<view class="text_t">
							{{item.title}}
						</view>
						<view class="text_c">
							<u-parse :content="item.content" :tagStyle="style"></u-parse>
						</view>
						<view class="text_b">
							<view class="">
								{{dateFormat(item.updateTime) }}

							</view>
						</view>
					</view>
				</view>
				<u-loadmore :status="status" color="#fff" />
			</view>
		</view>





	</view>
</template>
<script>
	import {
		getnewlist
	} from "@/api/index.js"
	export default {
		data() {
			return {
				code: '',
				pageNum: 1,
				list: [],
				hasNextPage: true,
				status: 'loadmore'
			}
		},
		onLoad() {
			let app = getApp();
			this.userLoginFlag = app.globalData.userLogin;
			console.log(app.globalData.userLogin);
			this.getnewlists()
		},
		onShow() {

		},
		methods: {
			async getnewlists() {
				const {
					data,
					msg,
					status
				} = await getnewlist({
					params: {
						pageNum: this.pageNum,
						pageSize: 5
					}
				})
				if (status == 200) {
					this.list = data.list
					this.status = 'loadmore'
					this.hasNextPage = data.hasNextPage
				}
			},
			Godetail(e) {
				console.log(e);
				uni.navigateTo({
					url: '/pages/user/detail/detail?newsid=' + e
				})
			},

dateFormat(time) {
				let date = new Date(time);
				let year = date.getFullYear();
				// 在日期格式中，月份是从0开始的，因此要加0，使用三元表达式在小于10的前面加0，以达到格式统一  如 09:11:05
				let month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
				let day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
				let hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
				let minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
				let seconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
				// 拼接
				return year + "-" + month + "-" + day + " " + hours + ":" + minutes + ":" + seconds;
				// return year + "-" + month + "-" + day;
			},

		},
		onReachBottom() {
			this.status = 'loading';
			this.pageNum = ++this.pageNum;

			setTimeout(() => {
				if (this.hasNextPage) {
					this.getnewlists()

				}

				if (this.hasNextPage) {
					this.status = 'loading'
				} else {
					this.status = 'nomore'
					this.hasNextPage = false
				}
			}, 2000)
		}
	}
</script>
<style>
	page {
		background-color: #4f4a73 !important;
		height: 100% !important;
	}
</style>
<style lang="scss" scoped>
	.news {
		background-color: #4f4a73;
		height: 100%;
		width: 100%;
		padding-top: 20px;

		.contnet {
			background-color: #4f4a73;
			height: 100%;
		}
	}

	.index_contnet {
		width: 95%;
		margin: 0rpx auto;

		padding-bottom: 40rpx;

		.index_contnet_item {

			overflow: hidden;
			border-radius: 25rpx;
			background-color: #fff;
			width: 100%;
			height: 610rpx;
			margin-bottom: 40rpx;

			.text {
				color: $u-main-color;
				padding: 10rpx;

				.text_t {
					font-weight: 800;
				}

				.text_c {
					color: $u-content-color;

					display: -webkit-box; //对象作为弹性伸缩盒子模型显示
					overflow: hidden; //溢出隐藏
					-webkit-box-orient: vertical; //设置伸缩盒子对象的子元素的排列方式
					-webkit-line-clamp: 2; //设置 块元素包含的文本行数

					/deep/ image {
						display: none;
					}
				}

				.text_b {
					color: $u-content-color;
					text-align: end;
					padding-right: 40rpx;
					padding-bottom: 20rpx;
					
				}
			}
		}
	}
</style>
